#include <string.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
    char *number;
    char *name;
    struct node *next;
}Node;

void iner(Node* phead, int index,char * number,char *name);
//头插
void add(Node* phead,char * number,char *name);
void del(Node* phead,char *name);
void print(Node* phead);
int size = 0;
int main()
{
    Node* phead;
    phead =(Node*) malloc(sizeof(Node));

    phead->next = NULL;
    add(phead,"123456","liming");
    add(phead,"894946","xiao");
    add(phead,"526515","wang");
    iner(phead,1,"5899","g");
    print(phead);
    del(phead,"wang");
    print(phead);
    return 0;
}

void iner(Node* phead, int index,char * number,char *name)
{
    Node* a = phead;
    //找到节点
    for(int i = 1; i <= size - index ;i++)
    {
        a = a->next;
    }
    Node *new = malloc(sizeof(Node));
    new->name =name;
    new->number =number;

    new->next = a->next;
    a->next = new;
    
    size++;
}
//头插
void add(Node* phead,char * number,char *name)
{
    Node *new = malloc(sizeof(Node));
    new->name =name;
    new->number =number;
    if(phead->next == NULL)
    {
        phead->next = new;
        new->next = NULL;
    }
    else
    {
        new->next = phead->next;
        phead->next = new;
    }

    size++;
     
}
void del(Node* phead,char *name)
{
    Node *a = phead->next;
    Node *b = phead;
    while(a != NULL)
    {
        if(a->name == name)
        {
            b->next = a->next;
            printf("已将名字为%s的联系人删除\n", name);
            free(a);
            a = NULL;
            break;
        }
        a = a->next;
        b = b->next;
    }
}

void print(Node* phead)
{
    Node* tail = phead->next;
    while(tail != NULL)
    {
        printf("name:%s\n",tail->name);
        printf("number:%s\n",tail->number);
        tail = tail->next;
    }
}